package com.ytf.core.web.controller;

import com.ytf.core.common.Resp;
import com.ytf.core.web.application.RoleAppService;
import com.ytf.core.web.pojo.dto.RoleDto;
import com.ytf.core.web.pojo.vo.RoleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author YTF
 * @since 2025-05-20
 */
@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Autowired
    private RoleAppService roleAppService;

    @PostMapping
    public Resp<Void> insert(@RequestBody RoleDto roleDto){
        Boolean aBoolean = roleAppService.insert(roleDto);
        return aBoolean ? Resp.success():Resp.error();
    }

    @DeleteMapping("/{id}")
    public Resp<Void> deleteById(@PathVariable String id){
        roleAppService.deleteById(Long.valueOf(id));
        return Resp.success();
    }

    @PutMapping("/{id}")
    public Resp<Void> update(@PathVariable String id ,@RequestBody RoleDto roleDto){
        Boolean aBoolean = roleAppService.updateById(Long.valueOf(id),roleDto);
        return aBoolean ? Resp.success():Resp.error();
    }

    @GetMapping("/{id}")
    public Resp<RoleVo> getById(@PathVariable String id){
        RoleVo Vo = roleAppService.getById(Long.valueOf(id));
        return Vo != null ? Resp.success(Vo):Resp.error();
    }

}
